
import {
	cart_count
} from '@/api/order.js';


const COMMON = {
	// 购物车数量标记
	get_cart_count(){
		cart_count().then(res => {
			let text = `${ res.data }`;
			if(res.data){
				uni.setTabBarBadge({
					index: 2,
					text
				})
			}else{
				uni.hideTabBarRedDot({
					index: 2,
				})
			}
			
		})
	},

	// 登录跳转
	toLogin() {
		uni.navigateTo({
			url: '/pages/login/index'
		})
	},

	// 优惠券色系
	color: ['red', 'blue', 'violet', 'yellow'],


	// 提示弹框
	Toast(msg) {
		uni.showToast({
			title: msg,
			icon: "none"
		});
	},

	// 成功后返回上一页
	re_back(res) {
		uni.showToast({
			title: res.msg,
			icon: "none",
			success() {
				setTimeout(function() {
					uni.navigateBack()
				}, 1000);
			}
		});
	},

	// 复制文本
	value_copy(data) {
		uni.setClipboardData({
			data,
			success() {
				COMMON.Toast(`复制成功`);
			}
		})
	},

	// 支付
	wxPay(data) {
		uni.requestPayment({
			timeStamp: data.timeStamp,
			nonceStr: data.nonceStr,
			package: data.package,
			signType: data.signType,
			paySign: data.paySign,
			success(res) {
				uni.reLaunch({
					url: '/pages/order/index?type=0'
				})
			},
			fail(err) {
				uni.showToast({
					title: '订单未支付',
					icon: "none",
					success() {
						setTimeout(function() {
							uni.reLaunch({
								url: '/pages/order/index?type=1'
							})
						}, 1000);
					}
				});
			}
		});
	}


}

export {
	COMMON
}